package com.xm_jd.model.dao;

import java.util.List;


import com.xm_jd.model.entitys.Balance;
import com.xm_jd.model.entitys.car;
import com.xm_jd.model.entitys.tb_car;
import com.xm_jd.model.entitys.tb_dd;
import com.xm_jd.model.entitys.tb_sh;
import com.xm_jd.utils.BaseDao;

/**
 * ����ҳ���dao��
 * @author lenovo
 *
 */
public class BalanceDao {
			BaseDao<Balance> bdao=new BaseDao<>(Balance.class);
			BaseDao<tb_sh> dzdao=new BaseDao<>(tb_sh.class);
			BaseDao<tb_dd> ddao=new BaseDao<>(tb_dd.class);
			
			/**
			 * �������������Ʒ�б�  ������ϲ�ѯ����Ʒ��  �û��� ͼƬ�� ���ﳵ��
			 * @param uid
			 * @return
			 */
			public List<Balance> getBalance(int uid){
				String sql="SELECT * FROM tb_shoop INNER JOIN tb_car ON tb_shoop.`shoop_Id`=tb_car.`car_shoop_sid`"
						+" INNER JOIN tb_user ON tb_car.`car_user_id`=tb_user.`user_id` "
						+" INNER JOIN tb_picture ON tb_shoop.`shoop_Id`=tb_picture.`picture_shoop_Id`"
						+ " WHERE picture_zcg=1 AND user_id=? AND car_xuanzhong=1";
				return bdao.selectAll(sql, new Object[]{uid});
			}
			
			/**
			 * ��ʾ��Ʒ����ʱ����ϸ��Ϣ
			 * @param userid
			 * @param goodsid
			 * @return
			 */
			public Balance getAccount(int userid,int goodsid){
				String sql="SELECT * FROM tb_shoop INNER JOIN tb_car ON tb_shoop.`shoop_Id`=tb_car.`car_shoop_sid`"
							+" INNER JOIN tb_user ON tb_car.`car_user_id`=tb_user.`user_id` "
							+" AND tb_user.`user_id`=? AND tb_shoop.`shoop_Id`=?";
				List<Balance> list = bdao.selectAll(sql,new Object[]{userid,goodsid});
				if(list.size()>0){
					return list.get(0);
				}
				return null;
			}
			
			/**����ַ�������Ʒ
			 * @param sum
			 * @return
			 */
			public int addgood(tb_sh sh){
				String sql="INSERT INTO tb_sh(sh_name,sh_xxdz,sh_phone,sh_user_id,sh_ismr,sh_address) VALUES(?,?,?,?,?,?)";
				return bdao.executeUpdate(sql, new Object[]{sh.getSh_name(),sh.getSh_xxdz(),sh.getSh_phone(),sh.getSh_user_id(),sh.getSh_ismr(),sh.getSh_address()});
			}
			
			public List<tb_sh> selectSh(int uid){
				String sql="SELECT * FROM tb_sh where sh_user_id=? order by sh_ismr desc";
				return dzdao.selectAll(sql, new Object[]{uid});
			}
			
			/**
			 * @param id
			 * @param sid
			 * @return
			 */
			public tb_car getcarnum(int id,int sid){
				String sql="select * from tb_car where car_user_id=? and car_shoop_sid=?";
				BaseDao<tb_car> bdao=new BaseDao<>(tb_car.class);
				List<tb_car> list = bdao.selectAll(sql,new Object[]{id,sid});
				if(list.size()>0){
					return list.get(0);
				}
				return null;
			}		
			
			/**���û��������Ʒ��Ϣ���뵽��������
			 * @param id
			 * @return
			 */
			public int adddingdan(tb_dd id){
				String sql="insert into tb_dd(dd_id,dd_time,dd_user_id,dd_zmoney,dd_yfmoney,dd_ztai,dd_sh_id) value(?,?,?,?,?,?,?)";
				return ddao.executeUpdate(sql, new Object[]{id.getDd_id(),id.getDd_time(),id.getDd_user_id(),id.getDd_zmoney(),id.getDd_yfmoney(),id.getDd_ztai(),id.getDd_sh_id()});
			}
						
						
			/**���û��������Ʒ��Ϣ���뵽�굥����
			 * @param dd_id
			 * @param sid
			 * @param num
			 * @return
			 */
			public int addxiangdan(int dd_id,int sid,int num){
				String sql="insert into tb_xd(xd_dd_id,xd_shoop_id,xd_num)value(?,?,?)";
				return ddao.executeUpdate(sql, new Object[]{dd_id,sid,num});
			}
			
			/**ɾ�����ɶ�������Ʒ�Ķ�������
			 * @param car_id
			 * @return
			 */
			public int deletecar(int car_id){
				String sql="delete from tb_car where car_id=?";
				return ddao.executeUpdate(sql, new Object[]{car_id});
			}
			
			public int updatepay(int dinghao){
				String sql="update tb_dd set dd_ztai='待评价' where dd_id=?";
				return ddao.executeUpdate(sql, new Object[]{dinghao});
			}
			
			public int updatemoren(int userisd){
				String sql="update tb_sh set sh_ismr='0' where sh_user_id=?";
				return ddao.executeUpdate(sql, new Object[]{userisd});
			}
						
		
			
}
